package com.ifgi.sitcom.campusmapperNDrawer.adapters;
import com.ifgi.sitcom.campusmapperNDrawer.R;
import com.ifgi.sitcom.campusmapperNDrawer.controllers.CampusMapperApplication;
import com.ifgi.sitcom.campusmapperNDrawer.controllers.PlayerController;
import com.ifgi.sitcom.campusmapperNDrawer.gamedata.PlayerAdapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

		public class MenuListAdapter extends ArrayAdapter<String>
		{
		private final Context context;
		private final String[] itemName;
		private final int[] itemPicture;
		private PlayerAdapter player;
		
		public MenuListAdapter(Context applicationContext, String[] itemName,
				int[] itemPicture) {
			// TODO Auto-generated constructor stub
			super(applicationContext, R.layout.drawer_list_item, itemName);
			this.context = applicationContext;
			this.itemName = itemName;
			this.itemPicture = itemPicture;
			
		}
		@Override
		public View getView(int position, View view, ViewGroup parent) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View rowView=null;
			player= CampusMapperApplication.getInstance().getPlayer();
			if(position!=0)
			{
			rowView= inflater.inflate(R.layout.drawer_row, null, true);
			TextView txtTitle = (TextView) rowView.findViewById(R.id.text_drawer);
			ImageView imageView = (ImageView) rowView.findViewById(R.id.icon_drawer);
			txtTitle.setText(itemName[position-1]);
			txtTitle.setTextColor(context.getResources().getColor(R.color.selector_listview));
			imageView.setImageResource(itemPicture[position-1]);
			
			}
			else
			{
			rowView= inflater.inflate(R.layout.drawer_row_firstrow, null, true);
			rowView.setEnabled(false);
			rowView.setOnClickListener(null);
			TextView txtTitle = (TextView) rowView.findViewById(R.id.username_drawer_firstRow);
			TextView txtScore = (TextView) rowView.findViewById(R.id.score_drawer_firstRow);
			ImageView imageView = (ImageView) rowView.findViewById(R.id.icon_drawer_firstRow);
			Log.v(player.getUsername(), player.getUsername());
			txtTitle.setText(player.getUsername());
			txtScore.setText("General score: "+String.valueOf(player.getScoreTotal().getValue()));
			imageView.setImageBitmap(CampusMapperApplication.getInstance().getRoundedCornerBitmap(player.getPicture().bitmap, player.getPicture().bitmap.getWidth(), player.getPicture().bitmap.getHeight()));
			
			}
			return rowView;
			
		}
	
		}